<?php

//file to shift predefined image from directory to another directory

$src = $_POST['bgsrc'];


$keys = parse_url($src); // parse the url
$path = explode("/", $keys['path']); // splitting the path
$last = end($path); // get the value of the last element 
//exit($last);  //imgname.jpg

$packageType = $_POST['packageType'];

if ($packageType == 'BASIC')
    $src = "bgimgs2/" . $last;
else
    $src = "bgimgs/" . $last;
//exit($src);
$newsrc = "imagesapp/back.png";




$file = $src;
$newfile = $newsrc;

if (!copy($file, $newfile)) {
    echo "failed to copy $file...\n";
}

list($width, $height, $type, $attr) = getimagesize("imagesapp/back.png");
//echo ("w: ".$width."h: ".$height);//128 128

$aspectratio = $width / $height;
if ($aspectratio >= 1) {//width is greater than height
    if ($width > 580) {
        echo ("width100% ");

        $h = ceil(580 / $aspectratio);
        echo ($h);
    }
    else{
        echo("-h ".$width." ".$height);
    }
} else if ($aspectratio < 1) {
    if ($height > 350) {
        echo ("height100% ");
        $w = ceil(350 * $aspectratio);
        echo ($w);
    }
    else{
        echo("-w ".$width." ".$height);
    }
}

?>
